Use TokenRestrictions API for token creation#38
Merged
Conversation
These directories are generated by build tools (uv, pip, setuptools) and should not be tracked. https://claude.ai/code/session_01RbZveeSogxSnjJ5yr6AFtq
Adapt to Datasette's new token API: build a TokenRestrictions object using builder methods instead of separate restrict_all/restrict_database/ restrict_resource dicts, and await the now-async create_token() call. https://claude.ai/code/session_01RbZveeSogxSnjJ5yr6AFtq
Owner
Author
|
Tests will fail until I release Datasette 1.0a25 and depend on that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs:
This PR updates the token creation logic to use Datasette's
TokenRestrictionsAPI instead of manually managing restriction dictionaries.Summary
Refactored the
create_api_tokenview to leverage theTokenRestrictionsclass fromdatasette.tokens, simplifying the code and improving maintainability.Key changes
restrict_all,restrict_database,restrict_resource) withTokenRestrictions()instanceTokenRestrictionsmethods:allow_all(),allow_database(), andallow_resource()datasette.create_token()call toawait datasette.create_token()(now async)restrictionsparameter instead of individual restriction parameters.gitignoreentries forbuild/anddist/directoriesImplementation details
The
TokenRestrictionsclass provides a cleaner API for building token restrictions, eliminating the need for nested dictionary manipulation. The restriction building loop now directly calls methods on theTokenRestrictionsinstance, making the code more readable and less error-prone.https://claude.ai/code/session_01RbZveeSogxSnjJ5yr6AFtq